#include <nxos.h>

#define MAX_ARGS 1024

NX_Error TEST_PollWait(char *cmdline)
{
    NX_Solt solts[8];
    NX_PollState pState;
    solts[0] = NX_DeviceOpen("keyboard0", 0);

    while (1)
    {
        pState.inmask = NX_POLL_READ;
        if (NX_PollWait(solts, 1, -1, &pState) == NX_EOK)
        {
            NX_Printf("poll state %d %x %x\n", pState.solt, pState.inmask, pState.outmask);
            if (pState.outmask & NX_POLL_READ)
            {
                NX_InputEvent e;
                NX_MemZero(&e, sizeof(e));
                NX_DeviceRead(pState.solt, &e, 0, sizeof(e));
                NX_Printf("poll wait read key %x %x %x\n", e.code, e.type, e.value);
            }
            else
            {
                NX_Printf("poll wait mask err\n");
            }
        }
    }
    
    return NX_EOK;
}
